<template>
  <div id="activeManagementSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="审核内容">
          <el-select v-model="formInline.movieAuditTypeEnum" placeholder="">
            <el-option
              v-for="item in movieAuditTypeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="人审结果">
          <el-select v-model="formInline.manualVerify" clearable placeholder="">
            <el-option
              v-for="item in checkStatuList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="机审结果">
          <el-select v-model="formInline.autoVerify" clearable placeholder="">
            <el-option
              v-for="item in machineStatuList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="排序规则">
          <el-select v-model="formInline.orderWay" placeholder="请选择">
            <el-option
              v-for="(item, index) in orderWayList"
              :key="'item' + index"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="timeType">
          <el-select v-model="formInline.timeType" placeholder="">
            <el-option
              v-for="item in order2List"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="createTime">
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            class="datetimerange"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="标题查询">
          <el-input
            clearable
            v-model="formInline.content"
            placeholder="请输入标题查询"
          ></el-input>
        </el-form-item>
        <el-form-item label="用户搜索" prop="userValue">
          <el-input
            v-model="formInline.userValue"
            placeholder="请输入相应的搜索内容"
          >
            <el-select
              slot="prepend"
              v-model="formInline.userType"
              placeholder="请选择"
            >
              <el-option label="大鹏号" value="DAPENGACCOUNT"></el-option>
            </el-select>
          </el-input>
        </el-form-item>
        <el-form-item label="时间线" prop="timeLine">
          <el-select v-model="formInline.timeLine" placeholder="">
            <el-option
              v-for="item in timeLineList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核人" prop="verifyUserId">
          <el-select
            clearable
            v-model="formInline.verifyUserId"
            placeholder=""
            filterable
          >
            <el-option
              v-for="(item, index) in personList"
              :key="'item' + index"
              :label="item.nickname"
              :value="item.dapengUserId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="展示方式" prop="showType">
          <el-select v-model="formInline.showType" clearable placeholder="">
            <el-option
              v-for="item in displayRuleList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户属性" prop="userProperty">
          <el-select
            v-model="formInline.userProperty"
            clearable
            :disabled="disChoose"
          >
            <el-option
              v-for="item in userAttList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
import { getCreateTime } from '@utils/pubFunction'
import { getDpNum } from '@/api/system/user'

export default {
  name: 'ActiveManagementSearch',
  msg: '长视频内容-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          movieAuditTypeEnum: '', // 审核内容，单个（MOVIES_SINGLE）/批量（MOVIES_BATCH）
          autoVerify: '', // 机审结果
          manualVerify: '', // 人审结果
          orderWay: '', // 排序规则
          content: '', // 视频名称查询
          userType: '',
          userValue: '',
          verifyUserId: '', // 审核人
          showType: '', // 展示方式
          startTime: '',
          endTime: '',
          timeLine: '',
          timeType: '',
          userProperty: '', // 用户属性
          pubStartTime: '',
          pubEndTime: ''
        }
      }
    }
  },
  data() {
    return {
      disChoose: false, //用户属性，是否可选，false-可选
      // 人审结果
      checkStatuList: [{ dictLabel: '全部', dictValue: '' }],
      //审核内容
      movieAuditTypeList: [],
      // 机审结果
      autoVerifyList: [[{ dictLabel: '全部', dictValue: '' }]],
      machineStatuList: [{ dictLabel: '全部', dictValue: '' }],
      userAttList: [{ dictLabel: '全部', dictValue: '' }], // 用户属性
      // 排序
      orderWayList: [],
      // 排序2
      order2List: [],
      createTime: [],
      // 时间线
      timeLineList: [],
      // 审核人
      personList: [{ nickname: '全部', dapengUserId: '' }],
      // 展示方式
      displayRuleList: [{ dictLabel: '全部', dictValue: '' }],
      // 用户搜索
      searchList: [{ key: '大鹏号', value: 'DAPENGACCOUNT' }]
    }
  },
  mounted() {
    this.getStatusList()
    this.getCheckUser()
  },
  methods: {
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
      //设置默认数据
      this.setDefaultValue()
    },
    async getStatusList() {
      // 审核内容
      let movieAuditTypeList = await sysNormalDisable('movies_reviews_contents')
      this.movieAuditTypeList = this.movieAuditTypeList.concat(
        movieAuditTypeList
      )
      // 人审结果
      let data = await sysNormalDisable('long_video_people_status', 'result')
      this.checkStatuList = this.checkStatuList.concat(data)
      // 机审结果
      let machine = await sysNormalDisable(
        'long_video_machine_status',
        'result'
      )
      this.machineStatuList = this.machineStatuList.concat(machine)
      // 时间线
      let timeLine = await sysNormalDisable('long_video_timeLine')
      this.timeLineList = [...timeLine, { dictLabel: '全部', dictValue: '' }]
      // 排序规则
      let orderWayList = await sysNormalDisable('long_video_time_type')
      orderWayList.map((item) => {
        if (item.dictLabel === '机审时间正序') {
          item.dictValue = 'ASC2'
        }
        if (item.dictLabel === '机审时间倒序') {
          item.dictValue = 'DESC2'
        }
      })
      this.orderWayList = orderWayList
      // 顺序2
      this.order2List = await sysNormalDisable('sys_audit_search_type')
      // 展示方式
      let rule = await sysNormalDisable('long_video_displayRule', 'displayType')
      this.displayRuleList = this.displayRuleList.concat(rule)
      // 用户属性
      let UserAttr = await sysNormalDisable(
        'audit_user_property3',
        'jobCheckAttr'
      )
      this.userAttList = this.userAttList.concat(UserAttr)
      this.setDefaultValue()
      //触发列表获取权限
      this.$emit('toSearch')
    },
    /*设置默认数据*/
    setDefaultValue() {
      this.formInline.movieAuditTypeEnum = this.movieAuditTypeList[0].dictValue
      this.formInline.manualVerify = this.checkStatuList[0].dictValue
      this.formInline.autoVerify = this.machineStatuList[0].dictValue
      this.formInline.orderWay = this.orderWayList[0].dictValue
      this.formInline.timeLine = this.timeLineList[0].dictValue
      this.formInline.timeType = this.order2List[0].dictValue
      this.formInline.userType = this.searchList[0].value
      this.formInline.content = ''
      this.createTime = []
    },
    // 审核人
    getCheckUser() {
      getDpNum({ type: 'OPERATORS' }, (response) => {
        this.personList = this.personList.concat(response)
      })
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    },
    'formInline.movieAuditTypeEnum': {
      handler(newVal, oldVal) {
        if (newVal && newVal === 'MOVIES_BATCH') {
          //批量
          this.formInline.userProperty = 'VEST'
          this.disChoose = true
        } else {
          this.formInline.userProperty = ''
          this.disChoose = false
        }
      },
      deep: true
    }
  }
}
</script>

<style lang="less">
#activeManagementSearch {
  .el-input {
    &.el-input--suffix {
      width: 182px !important;
    }
  }
}
</style>
